package com.lg.service.impl;

import java.io.Serializable;
import java.sql.SQLException;
import java.util.Collection;
import java.util.List;

import org.apache.log4j.Logger;

import com.lg.dao.BaseDAO;
import com.lg.dao.Criteria;
import com.lg.dao.EntityDAO;
import com.lg.dao.Example;
import com.lg.serivce.GenericService;

abstract public class GenericServiceImpl<T extends Serializable>  implements GenericService<T> {
	protected Logger logger = Logger.getLogger(this.getClass().getName());
	private BaseDAO baseDAO;
	private EntityDAO<T> entityDAO;

	public BaseDAO getBaseDAO() {
		return baseDAO;
	}

	public void setBaseDAO(BaseDAO baseDAO) {
		this.baseDAO = baseDAO;
	}

	public EntityDAO<T> getEntityDAO() {
		return entityDAO;
	}

	public void setEntityDAO(EntityDAO<T> entityDAO) {
		this.entityDAO = entityDAO;
	}

	public Object add(T record) throws SQLException {
		return entityDAO.insert(record);
	}

	public void addBatch(Collection<T> conllection) throws SQLException {
		entityDAO.insertBatch(conllection);
	}

	public Object addSelective(T record) throws SQLException {
		return entityDAO.insertSelective(record);
	}

	public <C extends Criteria> int countByExample(Example<C> example)
			throws SQLException {
		return entityDAO.countByExample(example);
	}

	public int countByStatementId(String statementId, Object param)
			throws SQLException {
		return entityDAO.countByStatementId(statementId, param);
	}

	public T getByPrimaryKey(T id) throws SQLException {
		return entityDAO.selectByPrimaryKey(id);
	}

	public <C extends Criteria> List<T> getListByExample(Example<C> example)
			throws SQLException {
		return entityDAO.selectListByExample(example);
	}

	public <C extends Criteria> List<T> getListByExample(Example<C> example,
			int start, int count) throws SQLException {
		return entityDAO.selectListByExample(example, start, count);
	}

	public List<T> getListByStatementId(String statementId, Object param)
			throws SQLException {
		return entityDAO.selectListByStatementId(statementId, param);
	}

	public List<T> getListByStatementId(String statementId, Object param,
			int start, int count) throws SQLException {
		return entityDAO.selectListByStatementId(statementId, param, start,
				count);
	}

	public <C extends Criteria> T getObjectByExample(Example<C> example)
			throws SQLException {
		return entityDAO.selectObjectByExample(example);
	}

	public T getObjectByStatementId(String statementId, Object param)
			throws SQLException {
			return entityDAO.selectObjectByStatementId(statementId, param);
	}

	public <C extends Criteria> int modifyByExample(T record, Example<C> example)
			throws SQLException {
		return entityDAO.updateByExample(record, example);
	}

	public <C extends Criteria> int modifyByExampleSelective(T record,
			Example<C> example) throws SQLException {
		return entityDAO.updateByExampleSelective(record, example);
	}

	public int modifyByPrimaryKey(T record) throws SQLException {
		return entityDAO.updateByPrimaryKey(record);
	}

	public int modifyByPrimaryKeySelective(T record) throws SQLException {
		return entityDAO.updateByPrimaryKeySelective(record);
	}

	public <C extends Criteria> int removeByExample(Example<C> example)
			throws SQLException {
		return entityDAO.deleteByExample(example);
	}

	public int removeByPrimaryKey(T id) throws SQLException {
		return entityDAO.deleteByPrimaryKey(id);
	}
	public Object addByStatementId(String statementId,Object param) throws SQLException{
		return entityDAO.insertByStatementId(statementId, param);
	}
	public int modifyByStatementId(String statementId,Object param) throws SQLException{
		return entityDAO.updateyStatementId(statementId, param);
	}
	public int removeByStatementId(String statementId,Object param)throws SQLException{
		return entityDAO.deleteByStatementId(statementId, param);
	}

}
